package com.yj.config.spring;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;

import java.util.concurrent.Executor;

/**
 * Copyright 2017 (C) Yunjian-VC
 * Created on : 2017/12/11
 * Author     : Unbelievable9
 **/
@Configuration
@EnableAsync(proxyTargetClass = true)
public class AsyncConfig extends AsyncSupportConfigurer {

    private final Logger logger = LogManager.getLogger(AsyncConfig.class);

    @Bean
    public Executor getAsyncExecutor() {
        logger.log(Level.DEBUG, "Create Async Task Executor");

        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(50);
        executor.setQueueCapacity(10000);
        executor.setThreadNamePrefix("ymvs");

        return executor;
    }
}
